﻿(function ($) {
    oo('class', {
        prop: [
            {
                name: 'ui',
                setter: function (value) {
                    this('string' == typeof value ? $('#' + value) : value);
                },
                getter: function () {
                    if (null == this) {
                        alert('请设置UI属性!');
                        return;
                    }
                    return this;
                }
            },
            {
                name: 'options',
                setter: function (value, owner) {
                    var op = $.extend({}, owner.prop('options'), value);
                    if (op.hasOwnProperty('mode') && op.mode == 'remote' && op.hasOwnProperty('url')) {
                        if (op.hasOwnProperty('extraData')) {
                            op.url = owner.getRemoteUrl(op.url, op.extraData);
                            delete op.extraData;
                        }
                        else {
                            op.url = oo('ajax', op.url).prop('url');
                        }
                    }
                    this(op);
                }
            }
        ],
        _easyui: function (op) {
            this.prop('options', op);
        },
        call: function (arg1, arg2) {
            var returnValue = this.prop('ui')[this.prop('className')](arg1, arg2);
            return returnValue == this.prop('ui') ? this : returnValue;
        },
        render: function () {
            var op;
            (op = this.prop('options')) ? this.call(this.prop('options')) : console.log('请检查easyui.options!');
        },
        bind: function (data) {
            this.call('loadData', data);
        },
        getRemoteUrl: function (method, data) {
            var params = [];
            $.each(data, function (k, v) {
                params.push([k, 'object' == typeof v ? $.toJSON(v) : v].join('='));
            });
            return oo('ajax', method).prop('url') + (params.length ? ('?' + params.join('&')) : '');
        }
    });
})(jQuery);